﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;
using System.Data;

/// <summary>
///GpzjDAL 的摘要说明
/// </summary>
public class GpzjDAL
{
    /// <summary>
    /// 插入一条股票战略
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    public bool InsertGpzj(Gpzj model)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("MrTime", SqlDbType.DateTime, model.MrTime);
            tool.AddSqlParameter("Name", SqlDbType.VarChar, model.Name);
            tool.AddSqlParameter("Link", SqlDbType.VarChar, model.Link);
            tool.AddSqlParameter("UpDown", SqlDbType.VarChar, model.UpDown);
            int rValue = SqlHelper.ExecuteNonQuery(DBManager.WebSite, System.Data.CommandType.StoredProcedure, "InsertGpzj", tool.GetSqlParameters());
            if (rValue > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch (Exception exsql)
        {
            return false;
        }
    }

    /// <summary>
    /// 更新一条记录
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    public bool Update(Gpzj model)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("id", SqlDbType.Int, model.Id);
            tool.AddSqlParameter("MrTime", SqlDbType.DateTime, model.MrTime);
            tool.AddSqlParameter("Name", SqlDbType.VarChar, model.Name);
            tool.AddSqlParameter("Link", SqlDbType.VarChar, model.Link);
            tool.AddSqlParameter("UpDown", SqlDbType.VarChar, model.UpDown);
            int rValue = SqlHelper.ExecuteNonQuery(DBManager.WebSite, System.Data.CommandType.StoredProcedure, "[UpdateGpzj]", tool.GetSqlParameters());
            if (rValue > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch (Exception exsql)
        {
            return false;
        }
    }

    public bool Delete(int id)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("id", SqlDbType.Int, id);
            int rValue = SqlHelper.ExecuteNonQuery(DBManager.WebSite, System.Data.CommandType.StoredProcedure, "DeleteGpzj", tool.GetSqlParameters());
            if (rValue == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch (Exception exsql)
        {
            return false;
        }

    }

    /// <summary>
    /// 得到所有的
    /// </summary>
    /// <returns></returns>
    public List<Gpzj> GetTop50()
    {
        DataTable dt = SqlHelper.ExecuteGetTable(DBManager.WebSite, System.Data.CommandType.StoredProcedure, "GetRxtGpzj", null);
        List<Gpzj> lstSuccess = new List<Gpzj>();
        foreach (DataRow reader in dt.Rows)
        {
            Gpzj s = new Gpzj();
            s.Id = Tools.GetInt(reader["Id"]);
            s.Name = Tools.GetString(reader["Name"]);
            s.Link = Tools.GetString(reader["Link"]);
            s.UpDown = Tools.GetString(reader["UpDown"]);
            s.MrTime = Tools.GetDateTime(reader["MrTime"]);
            lstSuccess.Add(s);
        }
        return lstSuccess;
    }

    public Gpzj GetElementById(int id)
    {
        Tools tool = new Tools();
        tool.AddSqlParameter("id", SqlDbType.Int, id);
        DataTable tb = SqlHelper.ExecuteGetTable(DBManager.WebSite, CommandType.StoredProcedure, "GetGpzjById", tool.GetSqlParameters());
        Gpzj s = null;
        if (tb.Rows.Count > 0)
        {
            s = new Gpzj();
            DataRow row = tb.Rows[0];
            s.Id = Tools.GetInt(row["Id"]);
            s.Name = Tools.GetString(row["Name"]);
            s.Link = Tools.GetString(row["Link"]);
            s.UpDown = Tools.GetString(row["UpDown"]);
            s.MrTime = Tools.GetDateTime(row["MrTime"]);
        }
        return s;
    }
}